import json
from flask import Flask, request, jsonify, Response
from utils import crawl_util
from utils import draw_temp_pic
from flask_cors import CORS
import time
app = Flask(__name__)
CORS(app)


@app.route('/weather', methods=['POST'])
def crawl():
    province = request.json.get('selectedProvince')
    cu = crawl_util.CrawlUtil(province)
    dict_of_temp = cu.crawl_seven_day_temperature()
    img_url_dict = draw_temp_pic.show_template(dict_of_temp, province)
    return jsonify(img_url_dict)


if __name__ == '__main__':
    app.run(debug=True)

